package com.se.service;

import com.se.dao.mysql.ActDao;
import com.se.domain.mysql.ActivityDO;
import com.se.enums.ResultCode;
import com.se.exception.ResultException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class ActService {

    @Autowired
    ActDao actDao;
    public ActivityDO checkModifyAct(Long actId, Long userId) throws ResultException {
        ActivityDO activityDO = actDao.getByActId(actId);
        if(activityDO == null){
            throw new ResultException(ResultCode.NO_OBJECT);
        }
        if(!Objects.equals(userId, activityDO.getUserId())){
            throw new ResultException(ResultCode.NO_PERM);
        }
        return activityDO;
    }

    public boolean checkPublish(ActivityDO activityDO){
        return activityDO.getPublish() && activityDO.getQnId() != null;
    }
}
